<!--
 * @Description: 预约单打印
 * @Autor: 何兴家
 * @Date: 2021-02-07 09:24:05
 * @LastEditors: 何兴家
 * @LastEditTime: 2021-04-09 14:00:06
-->
<template>
  <div style="margin-right: 10px; margin-right: 10px; display: inline-block;">
    <AjaxButton type="primary" :disabled="disabled" :click="handlePrint">{{ btnText }}</AjaxButton>

    <BasePrint ref="print" :data="printData" :showTopIcon="true" :title="printTitle" template="repair/bookingOrder" />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { confirmAction, notifyAction, findFormItem, findTableItem } from '@/utils';
import { printPrecontractOrder } from '@/api/repair/repairReception/precontractArrange';
import { getNameByIds } from '@/api/repair/common';
import { getAppId } from '@/assets/js/auth';

export default {
  props: {
    orderNo: {
      type: String,
      default: ''
    },
    btnText: {
      type: String,
      default: '打印单据'
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  mixins: [dictionary],
  data() {
    return {
      printData: {}
    };
  },
  computed: {
    printTitle() {
      return (getAppId() == 'beijing' ? '北京汽车' : '蓝谷极狐') + '售后服务预约登记表';
    }
  },
  methods: {
    // 点击打印
    async handlePrint() {
      let res = await printPrecontractOrder({ bookingOrderNo: this.orderNo });
      if (res.resultCode == 200) {
        // 翻译人名
        try {
          let nameIdArr = [res.data.bookServiceAdvisor, res.data.chiefTechnician];
          if (nameIdArr[0] || nameIdArr[1]) {
            let nameRes = await getNameByIds({ userIds: nameIdArr.join(',') });
            if (nameRes.resultCode == 200) {
              res.data.bookServiceAdvisor = nameRes.data.find(item => item.employeeId == res.data.bookServiceAdvisor).employeeName;
            }
          }
        } catch (err) {
          console.error(err, '翻译人名失败');
        }
        this.printData = res.data;
        this.$refs.print.EXCUTE_PRINT();
      }
    }
  }
};
</script>

<style scoped></style>
